package com.mk.wardsystemserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mk.wardsystemserver.pojo.MenuRole;
import com.mk.wardsystemserver.mapper.MenuRoleMapper;
import com.mk.wardsystemserver.pojo.RespBean;
import com.mk.wardsystemserver.service.IMenuRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhoubin
 * @since 2022-02-24
 */
@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements IMenuRoleService {

    @Autowired
    private  MenuRoleMapper menuRoleMapper;
    /**
     * 更新角色菜单
     *
     * @param rid
     * @param mids
     * @return
     */
    @Override
    //事务注解
    @Transactional
    public RespBean updateMenuRole(Integer rid, Integer[] mids) {
        //删除了角色下面的所有菜单
        menuRoleMapper.delete(new QueryWrapper<MenuRole>().eq("rid",rid));
        //要先删除在提示，如果提示了的话就不会走删除
        if(null==mids||0==mids.length){
            return RespBean.success("更新成功");
        }
        Integer result= menuRoleMapper.insertRecord(rid,mids);
        if(result==mids.length){
            return RespBean.success("更新成功！");
        }
        else {
            return RespBean.success("更新失败！");
        }

    }
}
